package model.ability;

import model.effects.Effect;
import model.entity.Entity;
import model.stats.StatsContainer;

/**
 * Defines the interface for MapAbility (from map) abilities:
 * SelfMapAbility, RangedMapAbility
 * @author Zachary
 */
public abstract class MapAbility extends Ability implements DoFromMap{
	private Effect baseEffect;
	private StatsContainer casterStats;
	private AbilityType type;
	
	/**
	 * Protected constructor for MapAbility.
	 * @param name
	 * @param ps
	 * @param mana
	 * @param delay
	 */
	protected MapAbility(String name, PassiveSkill ps, int mana, int delay,
			Effect baseEffect, AbilityType at) {
		super(name, ps, mana, delay);
		this.baseEffect = baseEffect;
		this.type = at;
	}
	/**
	 * Derive the actual effect a target Entity will experience.
	 * Based on the caster's stats (some of them) and the skill level
	 * of the caster's governing passive skill.
	 * @return
	 */
	protected Effect getDerivedEffect(Entity caster){
		double modification = type.getStatMulitiplier(caster.getStatsContainer()) 
		+ this.getSkillLevelMultiplier();
		this.baseEffect.modifyParameter(modification);
		return this.baseEffect;
	}
	
	/**
	 * Calculate the probability of a successful ability use.
	 * Based on the PassiveSkill level and is in the range
	 * [25 100] in R (as approximated by double).
	 * 
	 * To use this probability, get a random integer from 0 to 100.
	 * If it is less than the value returned from this method, do your
	 * action, otherwise do nothing.
	 * @return
	 */
	public double getSuccessProbability(){
		double passiveSkillProb = super.getSuccessProbability();
		double statsProb = type.getSuccessProbabilityBasedOnAbilityType(casterStats);
		return (passiveSkillProb + statsProb) / 2;
	}
}
